# encoding: utf-8
from __future__ import absolute_import, unicode_literals

# from daterange_filter.filter import DateRangeFilter
from django.contrib import admin
from django.utils.html import format_html

from apps.bookings import StatusFilter
from apps.bookings.models import Booking, Order
import datetime


# @admin.register(Booking)
class BookingAdmin(admin.ModelAdmin):
    list_display = ('id', 'user', 'court', 'date', 'start_time', 'end_time', 'status_colored')

    # list_display_links = ('id', 'date')
    # ordering = ('-creat_time',)
    # list_filter = ('date', DateRangeFilter)
    # list_filter = StatusFilter
    search_fields = ('start_time',)

    def status_colored(self, obj):
        if obj.end_time is None:
            return format_html('<span style="color:red">{}</span>', '未关灯')
        else:
            return format_html('<span style="color:green">{}</span>', '已关灯')

    status_colored.short_description = "状态"


class OrderAdmin(admin.ModelAdmin):
    list_display = ('id', 'user', 'date', 'uid', 'status_colored')

    # list_display_links = ('id', 'date')
    # ordering = ('-creat_time',)
    # list_filter = ('date', DateRangeFilter)
    # list_filter = StatusFilter
    search_fields = ('date', )

    def status_colored(self, obj):
        if obj.pay_status == 0:
            return format_html('<span style="color:red">{}</span>', '未支付')
        else:
            return format_html('<span style="color:green">{}</span>', '已支付')

    status_colored.short_description = "支付情况"


admin.site.unregister(Booking)
admin.site.unregister(Order)
admin.site.register(Booking, BookingAdmin)
admin.site.register(Order, OrderAdmin)
